home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WINGs / widgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-02  |  22.2 KB  |  1,011 lines

  1.  
  2.  
  3. #include "WINGsP.h"
  4.  
  5. #include <X11/Xutil.h>
  6.  
  7. #include <X11/cursorfont.h>
  8.  
  9. /********** data ************/
  10.  
  11.  
  12. #define CHECK_BUTTON_ON_WIDTH     16
  13. #define CHECK_BUTTON_ON_HEIGHT     16
  14.  
  15. static char *CHECK_BUTTON_ON[] = {
  16. "               %",
  17. " .............%#",
  18. " ........... .%#",
  19. " .......... #.%#",
  20. " ......... #%.%#",
  21. " ........ #%..%#",
  22. " ... #.. #%...%#",
  23. " ... #% #%....%#",
  24. " ... % #%.....%#",
  25. " ...  #%......%#",
  26. " ... #%.......%#",
  27. " ...#%........%#",
  28. " .............%#",
  29. " .............%#",
  30. " %%%%%%%%%%%%%%#",
  31. "%###############"};
  32.  
  33. #define CHECK_BUTTON_OFF_WIDTH     16
  34. #define CHECK_BUTTON_OFF_HEIGHT    16
  35.  
  36. static char *CHECK_BUTTON_OFF[] = {
  37. "               %",
  38. " .............%#",
  39. " .............%#",
  40. " .............%#",
  41. " .............%#",
  42. " .............%#",
  43. " .............%#",
  44. " .............%#",
  45. " .............%#",
  46. " .............%#",
  47. " .............%#",
  48. " .............%#",
  49. " .............%#",
  50. " .............%#",
  51. " %%%%%%%%%%%%%%#",
  52. "%###############"};
  53.  
  54. #define RADIO_BUTTON_ON_WIDTH     15
  55. #define RADIO_BUTTON_ON_HEIGHT    15
  56. static char *RADIO_BUTTON_ON[] = {
  57. ".....%%%%%.....",
  58. "...%%#####%%...",
  59. "..%##.....%.%..",
  60. ".%#%..    .....",
  61. ".%#.        ...",
  62. "%#..        .. ",
  63. "%#.          . ",
  64. "%#.          . ",
  65. "%#.          . ",
  66. "%#.          . ",
  67. ".%%.        . .",
  68. ".%..        . .",
  69. "..%...    .. ..",
  70. ".... .....  ...",
  71. ".....     .....",
  72. };
  73.  
  74. #define RADIO_BUTTON_OFF_WIDTH     15
  75. #define RADIO_BUTTON_OFF_HEIGHT    15
  76. static char *RADIO_BUTTON_OFF[] = {
  77. ".....%%%%%.....",
  78. "...%%#####%%...",
  79. "..%##.......%..",
  80. ".%#%...........",
  81. ".%#............",
  82. "%#............ ",
  83. "%#............ ",
  84. "%#............ ",
  85. "%#............ ",
  86. "%#............ ",
  87. ".%%.......... .",
  88. ".%........... .",
  89. "..%......... ..",
  90. ".... .....  ...",
  91. ".....     .....",
  92. };
  93.  
  94.  
  95. static char *BUTTON_ARROW[] = {
  96. "..................",
  97. "....##....#### ...",
  98. "...#.%....#... ...",
  99. "..#..%#####... ...",
  100. ".#............ ...",
  101. "#............. ...",
  102. ".#............ ...",
  103. "..#..          ...",
  104. "...#. ............",
  105. "....# ............"
  106. };
  107.  
  108. #define BUTTON_ARROW_WIDTH    18
  109. #define BUTTON_ARROW_HEIGHT    10
  110.  
  111.  
  112. static char *BUTTON_ARROW2[] = {
  113. "                  ",
  114. "    ##    ####.   ",
  115. "   # %    #   .   ",
  116. "  #  %#####   .   ",
  117. " #            .   ",
  118. "#             .   ",
  119. " #            .   ",
  120. "  #  ..........   ",
  121. "   # .            ",
  122. "    #.            "
  123. };
  124.  
  125. #define BUTTON_ARROW2_WIDTH    18
  126. #define BUTTON_ARROW2_HEIGHT    10
  127.  
  128.  
  129. static char *SCROLLER_DIMPLE[] = {
  130. ".%###.",
  131. "%#%%%%",
  132. "#%%...",
  133. "#%..  ",
  134. "#%.   ",
  135. ".%.  ."
  136. };
  137.  
  138. #define SCROLLER_DIMPLE_WIDTH   6
  139. #define SCROLLER_DIMPLE_HEIGHT  6
  140.  
  141.  
  142. static char *SCROLLER_ARROW_UP[] = {
  143. "....%....",
  144. "....#....",
  145. "...%#%...",
  146. "...###...",
  147. "..%###%..",
  148. "..#####..",
  149. ".%#####%.",
  150. ".#######.",
  151. "%#######%"
  152. };
  153.  
  154. static char *HI_SCROLLER_ARROW_UP[] = {
  155. "    %    ",
  156. "    %    ",
  157. "   %%%   ",
  158. "   %%%   ",
  159. "  %%%%%  ",
  160. "  %%%%%  ",
  161. " %%%%%%% ",
  162. " %%%%%%% ",
  163. "%%%%%%%%%"
  164. };
  165.  
  166. #define SCROLLER_ARROW_UP_WIDTH   9
  167. #define SCROLLER_ARROW_UP_HEIGHT  9
  168.  
  169.  
  170. static char *SCROLLER_ARROW_DOWN[] = {
  171. "%#######%",
  172. ".#######.",
  173. ".%#####%.",
  174. "..#####..",
  175. "..%###%..",
  176. "...###...",
  177. "...%#%...",
  178. "....#....",
  179. "....%...."
  180. };
  181.  
  182. static char *HI_SCROLLER_ARROW_DOWN[] = {
  183. "%%%%%%%%%",
  184. " %%%%%%% ",
  185. " %%%%%%% ",
  186. "  %%%%%  ",
  187. "  %%%%%  ",
  188. "   %%%   ",
  189. "   %%%   ",
  190. "    %    ",
  191. "    %    "
  192. };
  193.  
  194. #define SCROLLER_ARROW_DOWN_WIDTH   9
  195. #define SCROLLER_ARROW_DOWN_HEIGHT  9
  196.  
  197.  
  198.  
  199. static char *SCROLLER_ARROW_LEFT[] = {
  200. "........%",
  201. "......%##",
  202. "....%####",
  203. "..%######",
  204. "%########",
  205. "..%######",
  206. "....%####",
  207. "......%##",
  208. "........%"
  209. };
  210.  
  211. static char *HI_SCROLLER_ARROW_LEFT[] = {
  212. "        %",
  213. "      %%%",
  214. "    %%%%%",
  215. "  %%%%%%%",
  216. "%%%%%%%%%",
  217. "  %%%%%%%",
  218. "    %%%%%",
  219. "      %%%",
  220. "        %"
  221. };
  222.  
  223. #define SCROLLER_ARROW_LEFT_WIDTH   9
  224. #define SCROLLER_ARROW_LEFT_HEIGHT  9
  225.  
  226.  
  227. static char *SCROLLER_ARROW_RIGHT[] = {
  228. "%........",
  229. "##%......",
  230. "####%....",
  231. "######%..",
  232. "########%",
  233. "######%..",
  234. "####%....",
  235. "##%......",
  236. "%........"
  237. };
  238.  
  239. static char *HI_SCROLLER_ARROW_RIGHT[] = {
  240. "%        ",
  241. "%%%      ",
  242. "%%%%%    ",
  243. "%%%%%%%  ",
  244. "%%%%%%%%%",
  245. "%%%%%%%  ",
  246. "%%%%%    ",
  247. "%%%      ",
  248. "%        "
  249. };
  250.  
  251. #define SCROLLER_ARROW_RIGHT_WIDTH   9
  252. #define SCROLLER_ARROW_RIGHT_HEIGHT  9
  253.  
  254.  
  255. static char *POPUP_INDICATOR[] = {
  256. "        #==",
  257. " ......%#==",
  258. " ......%#%%",
  259. " ......%#%%",
  260. " %%%%%%%#%%",
  261. "#########%%",
  262. "==%%%%%%%%%",
  263. "==%%%%%%%%%"
  264. };
  265.  
  266. #define POPUP_INDICATOR_WIDTH    11
  267. #define POPUP_INDICATOR_HEIGHT     8
  268.  
  269.  
  270.  
  271. static char *PULLDOWN_INDICATOR[] = {
  272. "=#######=",
  273. "=%===== =",
  274. "==%=== ==",
  275. "==%=== ==",
  276. "===%= ===",
  277. "===%= ===",
  278. "====%===="
  279. };
  280. #define PULLDOWN_INDICATOR_WIDTH    9
  281. #define PULLDOWN_INDICATOR_HEIGHT     7
  282.  
  283.  
  284. #define CHECK_MARK_WIDTH     8
  285. #define CHECK_MARK_HEIGHT     10
  286.  
  287. static char *CHECK_MARK[] = {
  288. "======== ",
  289. "======= #",
  290. "====== #%",
  291. "===== #%=",
  292. " #== #%==",
  293. " #% #%===",
  294. " % #%====",
  295. "  #%=====",
  296. " #%======",
  297. "#%======="};
  298.  
  299.  
  300. #define STIPPLE_WIDTH 8
  301. #define STIPPLE_HEIGHT 8
  302. static unsigned char STIPPLE_BITS[] = {
  303.     0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa
  304. };
  305.  
  306.  
  307.  
  308.  
  309. extern void W_ReadConfigurations(void);
  310.  
  311.  
  312. static int userWidgetCount=0;
  313.  
  314.  
  315. /*****  end data  ******/
  316.  
  317.  
  318. static void
  319. renderPixmap(W_Screen *screen, Pixmap d, Pixmap mask, char **data, 
  320.          int width, int height)
  321. {
  322.     int x, y;
  323.     GC whiteGC = WMColorGC(screen->white);
  324.     GC blackGC = WMColorGC(screen->black);
  325.     GC lightGC = WMColorGC(screen->gray);
  326.     GC darkGC = WMColorGC(screen->darkGray);
  327.  
  328.  
  329.     if (mask)
  330.     XSetForeground(screen->display, screen->monoGC, 0);
  331.     
  332.     for (y = 0; y < height; y++) {
  333.     for (x = 0; x < width; x++) {
  334.         switch (data[y][x]) {        
  335.          case ' ':
  336.          case 'w':
  337.         XDrawPoint(screen->display, d, whiteGC, x, y);
  338.         break;
  339.  
  340.          case '=':
  341.         if (mask)
  342.             XDrawPoint(screen->display, mask, screen->monoGC, x, y);
  343.                
  344.          case '.':
  345.          case 'l':
  346.         XDrawPoint(screen->display, d, lightGC, x, y);
  347.         break;
  348.         
  349.          case '%':
  350.          case 'd':
  351.         XDrawPoint(screen->display, d, darkGC, x, y);
  352.         break;
  353.         
  354.          case '#':
  355.          case 'b':
  356.          default:
  357.         XDrawPoint(screen->display, d, blackGC, x, y);
  358.         break;
  359.         }
  360.     }
  361.     }
  362. }
  363.  
  364.  
  365.  
  366. static WMPixmap*
  367. makePixmap(W_Screen *sPtr, char **data, int width, int height, int masked)
  368. {
  369.     Pixmap pixmap, mask = None;
  370.     
  371.     pixmap = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 
  372.                sPtr->depth);
  373.     
  374.     if (masked) {
  375.     mask = XCreatePixmap(sPtr->display, W_DRAWABLE(sPtr), width, height, 1);
  376.     XSetForeground(sPtr->display, sPtr->monoGC, 1);
  377.     XFillRectangle(sPtr->display, mask, sPtr->monoGC, 0, 0, width, height);
  378.     }
  379.  
  380.     renderPixmap(sPtr, pixmap, mask, data, width, height);
  381.  
  382.     return WMCreatePixmapFromXPixmaps(sPtr, pixmap, mask, width, height,
  383.                       sPtr->depth);
  384. }
  385.  
  386.  
  387. #define T_WINGS_IMAGES_FILE  RESOURCE_PATH"/Images.tiff"
  388. #define T_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.tiff"
  389.  
  390. #define X_WINGS_IMAGES_FILE  RESOURCE_PATH"/Images.xpm"
  391. #define X_DEFAULT_OBJECT_ICON_FILE RESOURCE_PATH"/defaultIcon.xpm"
  392.  
  393.  
  394. static Bool
  395. loadPixmaps(WMScreen *scr)
  396. {
  397.     RImage *image, *tmp;
  398.     RColor gray;
  399.     RColor white;
  400.  
  401.     gray.red = 0xae;
  402.     gray.green = 0xaa;
  403.     gray.blue = 0xae;
  404.  
  405.     white.red = 0xff;
  406.     white.green = 0xff;
  407.     white.blue = 0xff;
  408.  
  409.     image = RLoadImage(scr->rcontext, T_WINGS_IMAGES_FILE, 0);
  410.     if (!image)
  411.     image = RLoadImage(scr->rcontext, X_WINGS_IMAGES_FILE, 0);
  412.     if (!image) {
  413.     wwarning("WINGs: could not load widget images file: %s", 
  414.          RMessageForError(RErrorCode));
  415.     return False;
  416.     }
  417.     /* home icon */
  418.     /* make it have a gray background */
  419.     tmp = RGetSubImage(image, 0, 0, 24, 24);
  420.     RCombineImageWithColor(tmp, &gray);
  421.     scr->homeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  422.     RDestroyImage(tmp);
  423.     /* make it have a white background */
  424.     tmp = RGetSubImage(image, 0, 0, 24, 24);
  425.     RCombineImageWithColor(tmp, &white);
  426.     scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  427.     RDestroyImage(tmp);
  428.  
  429.     /* trash can */
  430.     tmp = RGetSubImage(image, 104, 0, 24, 24);
  431.     RCombineImageWithColor(tmp, &white);
  432.     scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  433.     RDestroyImage(tmp);
  434.     tmp = RGetSubImage(image, 104, 0, 24, 24);
  435.     RCombineImageWithColor(tmp, &white);
  436.     scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  437.     RDestroyImage(tmp);
  438.     /* create dir */
  439.     tmp = RGetSubImage(image, 104, 24, 24, 24);
  440.     RCombineImageWithColor(tmp, &white);
  441.     scr->createDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  442.     RDestroyImage(tmp);
  443.     tmp = RGetSubImage(image, 104, 24, 24, 24);
  444.     RCombineImageWithColor(tmp, &white);
  445.     scr->altCreateDirIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  446.     RDestroyImage(tmp);
  447.     /* diskettes */
  448.     tmp = RGetSubImage(image, 24, 80, 24, 24);
  449.     RCombineImageWithColor(tmp, &white);
  450.     scr->disketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  451.     RDestroyImage(tmp);
  452.     tmp = RGetSubImage(image, 24, 80, 24, 24);
  453.     RCombineImageWithColor(tmp, &white);
  454.     scr->altDisketteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  455.     RDestroyImage(tmp);
  456.     /* unmount */
  457.     tmp = RGetSubImage(image, 0, 80, 24, 24);
  458.     RCombineImageWithColor(tmp, &white);
  459.     scr->unmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  460.     RDestroyImage(tmp);
  461.     tmp = RGetSubImage(image, 0, 80, 24, 24);
  462.     RCombineImageWithColor(tmp, &white);
  463.     scr->altUnmountIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  464.     RDestroyImage(tmp);
  465.  
  466.     /* Magnifying Glass Icon for ColorPanel */
  467.     tmp = RGetSubImage(image, 24, 0, 40, 32);
  468.     RCombineImageWithColor(tmp, &gray);
  469.     scr->magnifyIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  470.     RDestroyImage(tmp);
  471.     /* ColorWheel Icon for ColorPanel */
  472.     tmp = RGetSubImage(image, 0, 25, 24, 24);
  473.     scr->wheelIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  474.     RDestroyImage(tmp);
  475.     /* GrayScale Icon for ColorPanel */
  476.     tmp = RGetSubImage(image, 65, 0, 40, 24);
  477.     scr->grayIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  478.     RDestroyImage(tmp);
  479.     /* RGB Icon for ColorPanel */
  480.     tmp = RGetSubImage(image, 25, 33, 40, 24);
  481.     scr->rgbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  482.     RDestroyImage(tmp);
  483.     /* CMYK Icon for ColorPanel */
  484.     tmp = RGetSubImage(image, 65, 25, 40, 24);
  485.     scr->cmykIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  486.     RDestroyImage(tmp);
  487.     /* HSB Icon for ColorPanel */
  488.     tmp = RGetSubImage(image, 0, 57, 40, 24);
  489.     scr->hsbIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  490.     RDestroyImage(tmp);
  491.     /* CustomColorPalette Icon for ColorPanel */
  492.     tmp = RGetSubImage(image, 81, 57, 40, 24);
  493.     scr->customPaletteIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  494.     RDestroyImage(tmp);
  495.     /* ColorList Icon for ColorPanel */
  496.     tmp = RGetSubImage(image, 41, 57, 40, 24);
  497.     scr->colorListIcon = WMCreatePixmapFromRImage(scr, tmp, 128);
  498.     RDestroyImage(tmp);
  499.     
  500.     RDestroyImage(image);
  501.  
  502. #if 0
  503.     scr->defaultObjectIcon =
  504.     WMCreatePixmapFromFile(scr, T_DEFAULT_OBJECT_ICON_FILE);
  505.     if (!scr->defaultObjectIcon) { 
  506.     scr->defaultObjectIcon =
  507.         WMCreatePixmapFromFile(scr, X_DEFAULT_OBJECT_ICON_FILE);
  508.     }
  509.     if (!scr->defaultObjectIcon) {
  510.     wwarning("WINGs: could not load default icon file");
  511.     return False;
  512.     }
  513. #endif
  514.     return True;
  515. }
  516.  
  517.  
  518.  
  519. WMScreen*
  520. WMCreateSimpleApplicationScreen(Display *display)
  521. {
  522.     WMScreen *scr;
  523.     
  524.     scr = WMCreateScreen(display, DefaultScreen(display));
  525.     
  526.     scr->aflags.hasAppIcon = 0;
  527.     scr->aflags.simpleApplication = 1;
  528.     
  529.     return scr;
  530. }
  531.  
  532.  
  533.  
  534. WMScreen*
  535. WMCreateScreen(Display *display, int screen)
  536. {
  537.     return WMCreateScreenWithRContext(display, screen,
  538.                       RCreateContext(display, screen, NULL));
  539. }
  540.  
  541.  
  542. WMScreen*
  543. WMCreateScreenWithRContext(Display *display, int screen, RContext *context)
  544. {
  545.     W_Screen *scrPtr;
  546.     XGCValues gcv;
  547.     Pixmap stipple;
  548.     static int initialized = 0;
  549.     static char *atomNames[] = {
  550.     "_GNUSTEP_WM_ATTR",
  551.         "WM_DELETE_WINDOW",
  552.         "WM_PROTOCOLS",
  553.         "CLIPBOARD",
  554.         "XdndAware",
  555.         "XdndSelection",
  556.         "XdndEnter",
  557.         "XdndLeave",
  558.         "XdndPosition",
  559.         "XdndDrop",
  560.         "XdndFinished",
  561.         "XdndTypeList",
  562.         "XdndStatus",
  563.         "WM_STATE"
  564.     };
  565.     Atom atoms[sizeof(atomNames)/sizeof(char*)];
  566.  
  567.     if (!initialized) {
  568.  
  569.     initialized = 1;
  570.  
  571.     W_ReadConfigurations();
  572.  
  573.     assert(W_ApplicationInitialized());
  574.     }
  575.     
  576.     scrPtr = malloc(sizeof(W_Screen));
  577.     if (!scrPtr)
  578.     return NULL;
  579.     memset(scrPtr, 0, sizeof(W_Screen));
  580.     
  581.     scrPtr->aflags.hasAppIcon = 1;
  582.     
  583.     scrPtr->display = display;
  584.     scrPtr->screen = screen;
  585.     scrPtr->rcontext = context;
  586.  
  587.     scrPtr->depth = context->depth;
  588.  
  589.     scrPtr->visual = context->visual;
  590.     scrPtr->lastEventTime = 0;
  591.  
  592.     scrPtr->colormap = context->cmap;
  593.  
  594.     scrPtr->rootWin = RootWindow(display, screen);
  595.  
  596.     scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
  597.  
  598.     /* initially allocate some colors */
  599.     WMWhiteColor(scrPtr);
  600.     WMBlackColor(scrPtr);
  601.     WMGrayColor(scrPtr);
  602.     WMDarkGrayColor(scrPtr);
  603.     
  604.     gcv.graphics_exposures = False;
  605.     
  606.     gcv.function = GXxor;
  607.     gcv.foreground = W_PIXEL(scrPtr->white);
  608.     if (gcv.foreground == 0) gcv.foreground = 1;
  609.     scrPtr->xorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
  610.                   |GCGraphicsExposures|GCForeground, &gcv);
  611.  
  612.     gcv.function = GXxor;
  613.     gcv.foreground = W_PIXEL(scrPtr->gray);
  614.     gcv.subwindow_mode = IncludeInferiors;
  615.     scrPtr->ixorGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
  616.                    |GCGraphicsExposures|GCForeground
  617.                    |GCSubwindowMode, &gcv);
  618.  
  619.     gcv.function = GXcopy;
  620.     scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
  621.                    |GCGraphicsExposures, &gcv);
  622.  
  623.     scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction
  624.                    |GCGraphicsExposures, &gcv);
  625.  
  626.     
  627.     stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), 
  628.                     STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
  629.     gcv.foreground = W_PIXEL(scrPtr->darkGray);
  630.     gcv.background = W_PIXEL(scrPtr->gray);
  631.     gcv.fill_style = FillStippled;
  632.     gcv.stipple = stipple;
  633.     scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
  634.                   GCForeground|GCBackground|GCStipple
  635.                   |GCFillStyle|GCGraphicsExposures, &gcv);
  636.  
  637.     gcv.foreground = W_PIXEL(scrPtr->black);
  638.     gcv.background = W_PIXEL(scrPtr->white);
  639.     scrPtr->textFieldGC = XCreateGC(display, W_DRAWABLE(scrPtr),
  640.                     GCForeground|GCBackground, &gcv);
  641.  
  642.     /* we need a 1bpp drawable for the monoGC, so borrow this one */
  643.     scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
  644.  
  645.     scrPtr->stipple = stipple;
  646.  
  647.     scrPtr->useMultiByte = WINGsConfiguration.useMultiByte;
  648.  
  649.     scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 
  650.         WINGsConfiguration.defaultFontSize);
  651.  
  652.     scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 
  653.         WINGsConfiguration.defaultFontSize);
  654.  
  655.     if (!scrPtr->boldFont)
  656.     scrPtr->boldFont = scrPtr->normalFont;
  657.  
  658.     if (!scrPtr->normalFont) {
  659.     wwarning("could not load any fonts. Make sure your font installation"
  660.          "and locale settings are correct.");
  661.  
  662.     return NULL;
  663.     }
  664.  
  665.     scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
  666.                         CHECK_BUTTON_ON_WIDTH,
  667.                         CHECK_BUTTON_ON_HEIGHT, False);
  668.  
  669.     scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
  670.                         CHECK_BUTTON_OFF_WIDTH,
  671.                         CHECK_BUTTON_OFF_HEIGHT, False);
  672.  
  673.     scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
  674.                         RADIO_BUTTON_ON_WIDTH,
  675.                         RADIO_BUTTON_ON_HEIGHT, False);
  676.  
  677.     scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
  678.                         RADIO_BUTTON_OFF_WIDTH,
  679.                         RADIO_BUTTON_OFF_HEIGHT, False);
  680.  
  681.     scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, 
  682.                      BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, 
  683.                      False);
  684.  
  685.     scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
  686.                        BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, 
  687.                    False);
  688.  
  689.  
  690.     scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
  691.                     SCROLLER_DIMPLE_WIDTH,
  692.                     SCROLLER_DIMPLE_HEIGHT, False);
  693.  
  694.  
  695.     scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
  696.                  SCROLLER_ARROW_UP_WIDTH,
  697.                  SCROLLER_ARROW_UP_HEIGHT, True);
  698.  
  699.     scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
  700.                    SCROLLER_ARROW_DOWN_WIDTH,
  701.                    SCROLLER_ARROW_DOWN_HEIGHT, True);
  702.  
  703.     scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
  704.                    SCROLLER_ARROW_LEFT_WIDTH,
  705.                    SCROLLER_ARROW_LEFT_HEIGHT, True);
  706.  
  707.     scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
  708.                     SCROLLER_ARROW_RIGHT_WIDTH,
  709.                     SCROLLER_ARROW_RIGHT_HEIGHT, True);
  710.  
  711.     scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
  712.                  SCROLLER_ARROW_UP_WIDTH,
  713.                  SCROLLER_ARROW_UP_HEIGHT, True);
  714.  
  715.     scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
  716.                    SCROLLER_ARROW_DOWN_WIDTH,
  717.                    SCROLLER_ARROW_DOWN_HEIGHT, True);
  718.  
  719.     scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
  720.                    SCROLLER_ARROW_LEFT_WIDTH,
  721.                    SCROLLER_ARROW_LEFT_HEIGHT, True);
  722.  
  723.     scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
  724.                     SCROLLER_ARROW_RIGHT_WIDTH,
  725.                     SCROLLER_ARROW_RIGHT_HEIGHT, True);
  726.  
  727.     scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
  728.                     POPUP_INDICATOR_WIDTH,
  729.                     POPUP_INDICATOR_HEIGHT, True);
  730.  
  731.     scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
  732.                        PULLDOWN_INDICATOR_WIDTH,
  733.                        PULLDOWN_INDICATOR_HEIGHT, True);
  734.  
  735.     scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
  736.                    CHECK_MARK_WIDTH,
  737.                    CHECK_MARK_HEIGHT, True);
  738.  
  739.     loadPixmaps(scrPtr);
  740.  
  741.     scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
  742.  
  743.     scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
  744.  
  745.     {
  746.     XColor bla;
  747.     Pixmap blank;
  748.     
  749.     blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
  750.     XSetForeground(display, scrPtr->monoGC, 0);
  751.     XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
  752.  
  753.     scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank,
  754.                               &bla, &bla, 0, 0);
  755.     XFreePixmap(display, blank);
  756.     }
  757.  
  758. #ifdef HAVE_XINTERNATOMS
  759.     XInternAtoms(display, atomNames, sizeof(atomNames)/sizeof(char*), False,
  760.          atoms);
  761. #else
  762.     {
  763.     int i;
  764.     for (i = 0; i < sizeof(atomNames)/sizeof(char*); i++) {
  765.         atoms[i] = XInternAtom(display, atomNames[i], False);
  766.     }
  767.     }
  768. #endif
  769.     
  770.     scrPtr->attribsAtom = atoms[0];
  771.     
  772.     scrPtr->deleteWindowAtom = atoms[1];
  773.  
  774.     scrPtr->protocolsAtom = atoms[2];
  775.     
  776.     scrPtr->clipboardAtom = atoms[3];
  777.  
  778.     scrPtr->xdndAwareAtom = atoms[4];
  779.     scrPtr->xdndSelectionAtom = atoms[5];
  780.     scrPtr->xdndEnterAtom = atoms[6];
  781.     scrPtr->xdndLeaveAtom = atoms[7];
  782.     scrPtr->xdndPositionAtom = atoms[8];
  783.     scrPtr->xdndDropAtom = atoms[9];
  784.     scrPtr->xdndFinishedAtom = atoms[10];
  785.     scrPtr->xdndTypeListAtom = atoms[11];
  786.     scrPtr->xdndStatusAtom = atoms[12];
  787.  
  788.     scrPtr->wmStateAtom = atoms[13];
  789.     
  790.     scrPtr->rootView = W_CreateRootView(scrPtr);
  791.  
  792.  
  793.     scrPtr->balloon = W_CreateBalloon(scrPtr);
  794.  
  795.  
  796.     W_InitApplication(scrPtr);
  797.     
  798.     return scrPtr;
  799. }
  800.  
  801.  
  802. void 
  803. WMHangData(WMWidget *widget, void *data)
  804. {
  805.     W_VIEW(widget)->hangedData = data;
  806. }
  807.  
  808.  
  809. void*
  810. WMGetHangedData(WMWidget *widget)
  811. {
  812.     return W_VIEW(widget)->hangedData;
  813. }
  814.  
  815.  
  816.  
  817. void
  818. WMDestroyWidget(WMWidget *widget)
  819. {
  820.     W_DestroyView(W_VIEW(widget));
  821. }
  822.  
  823.  
  824. void
  825. WMSetFocusToWidget(WMWidget *widget)
  826. {
  827.     W_SetFocusOfTopLevel(W_TopLevelOfView(W_VIEW(widget)), W_VIEW(widget));
  828. }
  829.  
  830.  
  831. /*
  832.  * WMRealizeWidget-
  833.  *     Realizes the widget and all it's children.
  834.  * 
  835.  */
  836. void
  837. WMRealizeWidget(WMWidget *w)
  838. {
  839.     W_RealizeView(W_VIEW(w));
  840. }
  841.  
  842. void
  843. WMMapWidget(WMWidget *w)
  844. {        
  845.     W_MapView(W_VIEW(w));
  846. }
  847.  
  848.  
  849. static void
  850. makeChildrenAutomap(W_View *view, int flag)
  851. {
  852.     view = view->childrenList;
  853.     
  854.     while (view) {
  855.     view->flags.mapWhenRealized = flag;
  856.     makeChildrenAutomap(view, flag);
  857.     
  858.     view = view->nextSister;
  859.     }
  860. }
  861.  
  862.  
  863. void
  864. WMMapSubwidgets(WMWidget *w)
  865. {   
  866.     /* make sure that subwidgets created after the parent was realized
  867.      * are mapped too */
  868.     if (!W_VIEW(w)->flags.realized) {
  869.     makeChildrenAutomap(W_VIEW(w), True);
  870.     } else {
  871.     W_MapSubviews(W_VIEW(w));
  872.     }
  873. }
  874.  
  875.  
  876. void
  877. WMUnmapSubwidgets(WMWidget *w)
  878. {   
  879.     if (!W_VIEW(w)->flags.realized) {
  880.     makeChildrenAutomap(W_VIEW(w), False);
  881.     } else {
  882.     W_UnmapSubviews(W_VIEW(w));
  883.     }
  884. }
  885.  
  886.  
  887.  
  888. void
  889. WMUnmapWidget(WMWidget *w)
  890. {   
  891.     W_UnmapView(W_VIEW(w));
  892. }
  893.  
  894.  
  895. void
  896. WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color)
  897. {    
  898.     W_SetViewBackgroundColor(W_VIEW(w), color);
  899. }
  900.  
  901.  
  902. void
  903. WMMoveWidget(WMWidget *w, int x, int y)
  904. {
  905.     W_MoveView(W_VIEW(w), x, y);
  906. }
  907.  
  908.  
  909. void
  910. WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height)
  911. {
  912.     W_ResizeView(W_VIEW(w), width, height);
  913. }
  914.  
  915.  
  916.  
  917. W_Class
  918. W_RegisterUserWidget(void)
  919. {
  920.     userWidgetCount++;
  921.  
  922.     return userWidgetCount + WC_UserWidget - 1;
  923. }
  924.  
  925.  
  926.  
  927. RContext*
  928. WMScreenRContext(WMScreen *scr)
  929. {
  930.     return scr->rcontext;
  931. }
  932.  
  933.  
  934.  
  935. unsigned int 
  936. WMWidgetWidth(WMWidget *w)
  937. {
  938.     return W_VIEW(w)->size.width;
  939. }
  940.  
  941.  
  942. unsigned int
  943. WMWidgetHeight(WMWidget *w)
  944. {
  945.     return W_VIEW(w)->size.height;
  946. }
  947.  
  948.  
  949. Window
  950. WMWidgetXID(WMWidget *w)
  951. {
  952.     return W_VIEW(w)->window;
  953. }
  954.  
  955.  
  956. WMScreen*
  957. WMWidgetScreen(WMWidget *w)
  958. {
  959.     return W_VIEW(w)->screen;
  960. }
  961.  
  962.  
  963.  
  964. void
  965. WMScreenMainLoop(WMScreen *scr)
  966. {
  967.     XEvent event;
  968.     
  969.     while (1) {
  970.     WMNextEvent(scr->display, &event);
  971.     WMHandleEvent(&event);
  972.     }
  973. }
  974.  
  975.  
  976.  
  977. Display*
  978. WMScreenDisplay(WMScreen *scr)
  979. {
  980.     return scr->display;
  981. }
  982.  
  983.  
  984. int 
  985. WMScreenDepth(WMScreen *scr)
  986. {
  987.     return scr->depth;
  988. }
  989.  
  990.  
  991. unsigned int 
  992. WMScreenWidth(WMScreen *scr)
  993. {
  994.     return scr->rootView->size.width;
  995. }
  996.  
  997.  
  998. unsigned int
  999. WMScreenHeight(WMScreen *scr)
  1000. {
  1001.     return scr->rootView->size.height;
  1002. }
  1003.  
  1004.  
  1005. void 
  1006. WMRedisplayWidget(WMWidget *w)
  1007. {
  1008.     W_RedisplayView(W_VIEW(w));
  1009. }
  1010.  
  1011.